package tech.yunland.shop.domain.dao;

import com.moyuer.bsf.domain.dao.BaseDao;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import tech.yunland.shop.domain.model.Tag;

import java.util.List;

/**
 * @author: 王东阳<350456985@qq.com>
 * 16/4/1
 */
@Repository
public class TagDao extends BaseDao<Tag, String>{

	public Tag sameName(String name, String organId) {
		Tag result = null;//返回结果

		DetachedCriteria criteria = DetachedCriteria.forClass(Tag.class);
        criteria.add(Restrictions.eq("name", name));
        criteria.createCriteria("organ").add(Restrictions.idEq(organId));

        List<Tag> tags = this.findByCriteria(criteria);

        if (tags.size() == 0) {
			return result;
		}else {
			result = tags.get(0);
		}
		return result;
	}
}
